1. Field of the Invention
The present invention relates to a method, a computer program and a computer system for converting a program code running in multi-thread to a program code causing fewer lock collisions.
2. Description of the Related Art
In recent years, there has been an accelerated shift to so-called multi-core processor architectures, in which one central processing unit (“CPU”) includes a plurality of CPU cores. The multi-core is externally recognized as a single CPU, but internally recognized as more than one CPU. Multi-core technology enables an increase in computing performance of the entire CPU chip mainly through performing parallel processing. Multi-core technology drastically increases the number of hardware threads simultaneously executable by the processor. For example, Sun™ Niagara 2™ can execute 64 threads on a single CPU.
If a conventional program is executed on a processor capable of executing a plurality of threads simultaneously, there is a problem of performance deterioration in the processor caused by a lock collision. Lock collision refers to a state where, if a lock is acquired to enter a critical section requiring exclusive execution in one thread, the next step is not executed in other threads until the above lock is released. The thread in which the next step is not executed typically enters a spin loop or sleep state.
There are various causes of lock collision. Consideration will be given to a program in which retrieving data from a queue is frequently executed in a plurality of threads. Further, consideration will be given to a case where a statement on retrieval processing is described in a synchronized block for describing the processing which requires exclusive execution in the program code. The foregoing program acquires a lock every time the retrieving processing is invoked during run time of the program. Therefore, a lock collision frequently occurs. Accordingly, frequently occurring lock collisions cause system performance problems.
In June of 2007, the Sun™ Bug database reported as a bug a program having a program code structured similar to the above program code when the program acts as a bottleneck to system performance in a computer system capable of executing 32 hardware threads. In the report, the above problem is identified in the java.lang.ref.RereferenceQueue class of Sun JDK 1.5.0—13 having similarly-structured program code.
The poll( ) method corresponding to retrieval processing is a method of the above class and is modified in Sun JDK1.5.0—14. In the modification, a statement on the process of determining whether or not the queue is empty and exiting from the method if the queue is determined to be empty is inserted before a statement acquiring a lock in the implementation of the poll( ) method.
Martin Vechev, Eran Yahav, Deriving Linearizable Fine-Grained Concurrent Objects, PLDI'08, ACM 978-1-59593-860-2/08/06, Jun. 7 to 13, 2008 describes program code that is convertible to a program code having high concurrency by adding a marked bit to the program code and using the added marked bit and a compareAndSwap (CAS) instruction. The marked bit is added manually.